package org.lee.obs.service;

import org.lee.obs.LotteryResult;
import org.lee.obs.event.EventManager;
import org.lee.obs.event.listener.MQEventListener;
import org.lee.obs.event.listener.MessageEventListener;

/**
 * LotteryService
 *
 * @author dralee
 * @date 2021-11-23 18:46:09
 **/
public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {
        eventManager = new EventManager(EventManager.EventType.MESSAGE, EventManager.EventType.MQ);
        eventManager.subscribe(EventManager.EventType.MESSAGE, new MessageEventListener());
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
    }

    public LotteryResult draw(String uid) {
        LotteryResult result = doDraw(uid);
        eventManager.notify(EventManager.EventType.MESSAGE, result);
        eventManager.notify(EventManager.EventType.MQ, result);
        return result;
    }

    protected abstract LotteryResult doDraw(String uid);
}
